<template>
  <view class="header">
    <view class="nav" v-if="nav" :style="'height:' + navH"></view>
    <view class="box" v-if="box">
      <view class="block" v-if="back || text"></view>
      <view class="back" v-if="back" @tap="backPage">
        <view class="icon"></view>
      </view>
      <view class="text" v-if="text != ''">{{ text }}</view>
      <slot></slot>
    </view>
  </view>
</template>

<script>
import app from "@/utils/app";

export default {
  data() {
    return {
      navH: app.systemInfo.statusBarHeight + "px",
    };
  },
  options: {
    multipleSlots: true,
  },
  props: {
    nav: {
      type: Boolean,
      default: true,
    },
    box: {
      type: Boolean,
      default: true,
    },
    back: {
      type: Boolean,
      default: false,
    },
    text: {
      type: String,
      default: "",
    },
  },
  methods: {
    backPage() {
      uni.navigateBack({
        delta: 1,
        complete: () => {
          this.$emit("onBack");
        },
      });
    },
  },
};
</script>
<style scoped lang="scss">
.header {
  position: relative;
  width: 100%;
  .nav {
    position: relative;
    width: 100%;
  }
  .box {
    position: relative;
    width: 100%;
    height: 100rpx;
    display: flex;
    align-items: center;
    .block {
      position: relative;
      margin-left: 25rpx;
      width: 0;
      height: 100%;
    }
    .back {
      height: 50rpx;
      width: 40rpx;
      position: relative;
      .icon {
        width: 18rpx;
        height: 18rpx;
        background-color: transparent;
        border-color: #020202;
        border-style: solid;
        border-width: 5rpx 5rpx 0 0;
        transform: translate(0, -50%) rotate(-135deg);
        position: absolute;
        top: 50%;
        left: 0;
        box-sizing: content-box;
      }
    }
    .text {
      font-size: 36rpx;
      color: #333333;
      font-weight: 900;
      line-height: 1;
      text-align: center;
      position: absolute;
      width: 50%;
      left: 50%;
      transform: translateX(-50%);
    }
  }
}
</style>
